﻿
<?php 

    include 'loginYanZheng.php';

    weiDengLu();


?>

<!DOCTYPE html>
<html lang="ch">
	<meta charset="utf8">
	<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
<head>
	<title>线索上传</title>
	<style>
		body{

			padding:20px;
		}

		div[class^="layui-col-md"]{

			/*border:solid 1px  rgb(233,233,233);*/
			padding: 2px;
			
		}
		div[class="layui-row"]{

			margin-top:10px;
			
		}
	</style>

</head>
<body>
	
	<div style="height:30px;"></div>
	
	<div class="layui-filuid">
	    <div class="layui-row" >
	      <div class="layui-col-md2">
	              
	              <a href="jiemian.php"><i class="layui-icon layui-icon-left" style="font-size:20px"></i><div class="doc-icon-name">返回</div></a>

	      </div>
	    </div>
	    <hr>


		<div class="layui-row">

			<button type="button" class="layui-btn layui-bg-red" id="test3"><i class="layui-icon"></i>上传电话</button>

		</div>
		<div class="layui-row">

			<div class="layui-inline">
	         	 <label >日期选择：</label>
	        </div>
	        <div class="layui-input-inline">
	          	<input type="text" id="dateA" class="layui-input" style="width:200px;">
	        </div>
	        ~
	        <div class="layui-input-inline">
	         	<input type="text" id="dateB" class="layui-input" style="width:200px;">
			</div>
		</div>	
		<div class="layui-row">
				<button type="button" class="layui-btn layui-bg-red" onclick="updateTable()">查询</button>
		</div>

		<div class="layui-row" style="padding:10px;">

			
			<div class="layui-col-md12">

				
			</div>

			
		</div>
		<div class="layui-row">

			

			<button type="button" class="layui-btn layui-bg-red" onclick="importTellShenFeng()">导出指定省份数据</button>
			<div class="layui-input-inline">
				<input type="text" id="shengfeng" placeholder="输入要导出的省份"  class="layui-input" >
			</div>
			<button type="button" class="layui-btn layui-bg-red" onclick="importTellNotShenFeng()">导出非指定省份</button>
			
			<button type="button" class="layui-btn layui-bg-red" onclick="importTellChongFu()">导出重复数据</button>
			
			<button type="button" class="layui-btn layui-bg-red" onclick="importTellAll()">导出全部省份数据</button>

		</div>

		<div class="layui-row">

			<button type="button" class="layui-btn layui-bg-red" onclick="importModel()">导出短信系统模板</button>
			
			<button type="button" class="layui-btn layui-bg-red" onclick="importModelAI()">导出AI电话模板</button>
			
		</div>

		<div class="layui-row">

			<button type="button" class="layui-btn layui-bg-red" onclick="addRenWu()">导入硅基AI系统</button>
			<div class="layui-input-inline">
	         	<input type="text" id="planId"  placeholder="输入任务ID" class="layui-input" style="width:200px;">
			</div>
			<button type="button" class="layui-btn layui-bg-red rewuN"  data-btn="0">开始任务</button>
			<button type="button" class="layui-btn layui-bg-red rewuN"  data-btn="1">删除任务</button>
			<button type="button" class="layui-btn layui-bg-red rewuN"  data-btn="2">暂停任务</button>
			<button type="button" class="layui-btn layui-bg-red rewuN"  data-btn="3">停止任务</button>

		</div>


		<div class="layui-row">
			
				<div class="layui-col-md12">

					<div class="date_Count">
						
					</div>

					<table id="tellTable" lay-filter='tellTable'>
						
					</table>
					
				</div>

		</div>
		
	</div>

</body>


</html>

<script src="layui/layui.all.js"></script>

<script>
	
	var laydate=layui.laydate

	var myDate=new Date();

	var starDateY=myDate.getFullYear()+'-'+(myDate.getMonth()+1)+'-'+myDate.getDate()

	var day1 = new Date();

	 day1.setTime(day1.getTime()+24*1000*60*60);

	var endDateY = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();

	laydate.render(

	{
		elem:'#dateA',
		type:'date',
		value:starDateY
		
		}
	)
	laydate.render(

	{
		elem:'#dateB',
		type:'date',
		value:starDateY
		
		}
	)
    var ziZhangHao_field=[{'field':'riqi',title:'日期',sort:true},{'field':'tell',title:'手机号码',sort:true},{field:'shengFen',title:'省份',sort:true},{field:'city',title:'城市',sort:true}]	
	var table = layui.table;

	var cols=[ziZhangHao_field];

     table.render({

	         elem: '#tellTable'
	        // ,width:500
	        ,height:600
	        ,url: 'mingxi.php' //数据接口
	        ,method:'post'
	        ,where:{type:34,starTime:starDateY,endTime:starDateY}
	        ,page: false //开启分页
	        ,cols:cols
	        ,toolbar:true
	        ,page:true
	        ,limit:15
	        ,limits:true
	        ,defaultToolbar:['filter', 'exports', 'print',{ //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
						      title: '提示'
						      ,layEvent: 'LAYTABLE_TIPS'
						      ,icon: 'layui-icon-tips'
						    }]
			,done: function(res, curr, count){

				    $('.date_Count').text('共'+count+'条数据');

				    console.log(res)

				  }
      });


     function updateTable(){

     	var datstr=$('#dateA')[0].value

     	var datstr1=$('#dateB')[0].value

     	var date_rag=[datstr,datstr1];

          table.reload('tellTable',{
            where:{
              type:34,
              starTime:date_rag[0],
              endTime:date_rag[1]
            }
            ,done:function(res, curr, count){

				    $('.date_Count').text('共'+count+'条数据');

				  }

          })


     }

   
     //uploadAPI('#test3','mingxi.php',{'type':'35',sqlTable:'everyDayTell',uploadfile:'tell.xlsx'})

	//function uploadAPI(elem,url,data,erroElem){



		var upload=layui.upload;


		var layer=layui.layer;

		 

	  //第一个参数 拖拽上传的元素ID  String

	  //第二个参数接口API String

	  //第三个参数POST请求参数  对象 {type:'30',sqlTable:'mysql的表名',uploadfile:'上传服务器后的表名'}

	  //第四个参数显示错误信息的元素ID  String

	  upload.render({

	     elem:'#test3'
	    ,url: 'mingxi.php' //改成您自己的上传接口
	    ,accept:'file'
	    ,data:{'type':'35',sqlTable:'everyDayTell',uploadfile:'tell.xlsx'}
        ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
   			this.index= layer.load(); //上传loading
  		}
	    ,done: function(res){

	      layer.close(this.index)

	      layer.alert(res['success']);

	      console.log(res['success']);

	       updateTable();

	      $(erroElem).prepend(res['success']);
	    }

	  });

	//}



	function importTellShenFeng(){  //导出指定省份数据


		var layer=layui.layer;

		if($('#shengfeng')[0].value==''){

			alert('省份不能为空值')

		}else{

			var index=layer.load();

			var datstr=$('#dateA')[0].value

	     	var datstr1=$('#dateB')[0].value

	     	var date_rag=[datstr,datstr1];
	
			var queryForm = $("#queryTaizhangForm");
			var url='importTellShenFeng.php?starTime='+date_rag[0]+'&endTime='+date_rag[1]+'&shengFeng='+$('#shengfeng')[0].value
			var exportForm = $("<form action='"+url+"' method='post'></form>")     
			exportForm.append("<input type='hidden' name='jsonStr' value='123'/>")
			exportForm.serialize(); 
			$(document.body).append(exportForm);
			exportForm.submit();
			exportForm.remove(); 
			layer.close(index);


		}

		



	}

	function importTellNotShenFeng(){ //导出非指定省份数据


		var index=layer.load();

			var datstr=$('#dateA')[0].value

	     	var datstr1=$('#dateB')[0].value

	     	var date_rag=[datstr,datstr1];

			var queryForm = $("#queryTaizhangForm");
			var url='importTellNotShenFeng.php?starTime='+date_rag[0]+'&endTime='+date_rag[1]+'&shengFeng='+$('#shengfeng')[0].value
			var exportForm = $("<form action='"+url+"' method='post'></form>")     
			exportForm.append("<input type='hidden' name='jsonStr' value='123'/>")
			exportForm.serialize(); 
			$(document.body).append(exportForm);
			exportForm.submit();
			exportForm.remove(); 
			layer.close(index);


	}

	function importTellChongFu(){ //导出当天重复数据

			var index=layer.load();

			var datstr=$('#dateA')[0].value

	     	var datstr1=$('#dateB')[0].value

	     	var date_rag=[datstr,datstr1];

			var queryForm = $("#queryTaizhangForm");
			var url='importTellChongFu.php?starTime='+date_rag[0]+'&endTime='+date_rag[1]+'&shengFeng='+$('#shengfeng')[0].value
			var exportForm = $("<form action='"+url+"' method='post'></form>")     
			exportForm.append("<input type='hidden' name='jsonStr' value='123'/>")
			exportForm.serialize(); 
			$(document.body).append(exportForm);
			exportForm.submit();
			exportForm.remove(); 
			layer.close(index);

	}

	function importTellAll(){ 


		var index=layer.load();

			var datstr=$('#dateA')[0].value

	     	var datstr1=$('#dateB')[0].value

	     	var date_rag=[datstr,datstr1];
		
			var queryForm = $("#queryTaizhangForm");
			var url='importTellAll.php?starTime='+date_rag[0]+'&endTime='+date_rag[1]+'&shengFeng='+$('#shengfeng')[0].value
			var exportForm = $("<form action='"+url+"' method='post'></form>")     
			exportForm.append("<input type='hidden' name='jsonStr' value='123'/>")
			exportForm.serialize(); 
			$(document.body).append(exportForm);
			exportForm.submit();
			exportForm.remove(); 
			layer.close(index);

	}

	function importModel(){

		var index=layer.load();

			var datstr=$('#dateA')[0].value

	     	var datstr1=$('#dateB')[0].value

	     	var date_rag=[datstr,datstr1];
	
			var queryForm = $("#queryTaizhangForm");
			var url='importModel.php?starTime='+date_rag[0]+'&endTime='+date_rag[1]
			var exportForm = $("<form action='"+url+"' method='post'></form>")     
			exportForm.append("<input type='hidden' name='jsonStr' value='123'/>")
			exportForm.serialize(); 
			$(document.body).append(exportForm);
			exportForm.submit();
			exportForm.remove(); 
			layer.close(index);




	}

	function importModelAI(){

		var index=layer.load();

			var datstr=$('#dateA')[0].value

	     	var datstr1=$('#dateB')[0].value

	     	var date_rag=[datstr,datstr1];
	
			var queryForm = $("#queryTaizhangForm");
			var url='importModelAI.php?starTime='+date_rag[0]+'&endTime='+date_rag[1]
			var exportForm = $("<form action='"+url+"' method='post'></form>")     
			exportForm.append("<input type='hidden' name='jsonStr' value='123'/>")
			exportForm.serialize(); 
			$(document.body).append(exportForm);
			exportForm.submit();
			exportForm.remove(); 
			layer.close(index);




	}

	function addRenWu(){

		var datstr=$('#dateA')[0].value

     	var datstr1=$('#dateB')[0].value

     	var date_rag=[datstr,datstr1];

     	var planId=$('#planId').val()

     	if(planId!==''){

     		var index=layer.load();

	     	$.post('AIboot/api.php',{starTime:date_rag[0],endTime:date_rag[1],type:3,planId:planId},function(data,status){

	     		layer.msg(data['msg'])

	     		layer.close(index);

	     		//询问框
				layer.confirm('是否开始当前任务？',{

					  btn: ['当然','等会儿'] //按钮

					},function(){

					  

					  // $.post('AIboot/api.php',{type:4,planId:planId,opType:0,opurlType:'startCallPlan' },function(data,status){

					  // 		console.log(data)

					  // })

					  opRenWu('startCallPlan',planId,0,function(data){

					  	layer.msg(data['msg'], {icon: 1});
					  })

					  


					},function(){

					  layer.msg('明白了');

				});

	     	})

	     }else{

	     	layer.msg('没有任务ID')
	     }


	}

	$('.rewuN').click(function(e){


			var str=$(e.target).text()

			var planId=$('#planId').val()

			var layer=layui.layer;

			var index=layer.load()

			if(planId!==''){

				switch(str){

					case '开始任务':
						console.log(0)
						opRenWu('startCallPlan',planId,0,function(data){

							layer.close(index)
							layer.msg(data['msg'], {icon: 1});
						})
					break;
					case '删除任务':
						console.log(1)
						opRenWu('stopCallPlan',planId,1,function(data){
							layer.close(index)
							layer.msg(data['msg'], {icon: 1});
						})
					break;

					case '暂停任务':
						opRenWu('suspendCallPlan',planId,2,function(data){
							layer.close(index)
							layer.msg(data['msg'], {icon: 1});
						})

					break;

					case '停止任务':

						opRenWu('stopCallPlan',planId,3,function(data){
							layer.close(index)
							layer.msg(data['msg'], {icon: 1});
						})

					break;


				}
			}else{
				layer.close(index)
				layer.msg('没有任务ID', {icon: 1})

			}


	})


	function opRenWu(urlOp,planId,opType,call){

		//参数说明 urlOp suspendCallPlan 暂停 startCallPlan 开始  stopCallPlan 终止 delCallPlan 删除 
		//planId 任务ID
		//opType 操作类型 0-开始、 1-删除、 2-暂停、 3-停止  

		$.post('AIboot/api.php',{type:4,planId:planId,opType:opType,opurlType:urlOp },function(data,status){

			call(data)

	  	})


	}



	
</script>